package Chap03;
import java.util.HashMap;
import java.util.Scanner;
public class People {
    private String name;

    public People() {
    }

    public People(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    //方法：购买水果
    public HashMap<Goods, Integer> buyGoods(Goods[] goods) {
        HashMap<Goods, Integer> goodsList = new HashMap<>();
        while (true) {
            System.out.println("请选择您要买的东西(按0退出）：");
            Scanner sc = new Scanner(System.in);
            String want = sc.next();
            if (want.equals(0)) {
                break;
            } else {
                System.out.println("您需要购买多少斤:");
                int number = sc.nextInt();
                for (int i = 0; i < goods.length; i++) {
                    if (want.equals(goods[i].getName())) {
                        goodsList.put(goods[i], number);
                        break;
                    }
                }


            }

        }
        return  goodsList;
    }
}